jQuery(function ($) {
    window.App = Spine.Controller.create({
        el: $("body"),

        elements: {
            "#contentList": "contentList",
            "#hierarchyTree": "hierarchyTree"
        },

        events: {
            "click .refresh": "refresh"
        },

        init: function () {
            //            Cofe.Models.EntryList.fetch();

            this.contentList = ContentList.init({ el: this.contentList });
            this.hierarchyTree = HierarchyTree.init({ el: this.hierarchyTree });

            var changeHashPath = this.proxy(function () {

                var path = "";
                if (window.location.hash != undefined) {
                    path = decodeURI(window.location.hash.slice(1));
                }

                if (this.path != path) {
                    this.path = path;
                    this.App.trigger("pathChanged", "application", this.path);
                }

            });

            changeHashPath();

            $(window).bind("hashchange", this.proxy(function (event) {
                changeHashPath();
            }));

            this.App.bind("pathChanged", this.proxy(function (sender, path) {
                if (sender != "application") {
                    //                        this.App.trigger("pathChanged", "application", path);
                    this.path = path;
                    window.location.hash = path;
                }

            }));

            //            this.contentList.el.hide();

        },

        refresh: function () {
            this.App.trigger("refresh", "application");
        }
    }).init();
});